package com.newenergy.wisehome.ui.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.newenergy.wisehome.R;
import com.newenergy.wisehome.common.util.LocaleUtil;
import com.newenergy.wisehome.config.AppManager;
import com.newenergy.wisehome.data.bean.DeviceCategory;

import butterknife.BindView;
import butterknife.OnClick;
import me.yokeyword.fragmentation.ISupportFragment;

/**
 * Created by kyx on 2018/4/26.
 * 风扇灯操作页面--7203
 */

public class FanLampFragment extends BaseFragment {


    private static String ARG_FANLAMP = "arg_fanlamp";

    @BindView(R.id.btn_back)
    Button mBtnBack;
    @BindView(R.id.tv_back)
    TextView mTvBack;
    @BindView(R.id.tv_page)
    TextView mTvPage;
    @BindView(R.id.btn_lamp_switch)
    Button mBtnLampSwitch;
    @BindView(R.id.btn_fan_switch)
    Button mBtnFanSwitch;
    @BindView(R.id.btn_time1)
    Button mBtnTime1;
    @BindView(R.id.btn_time2)
    Button mBtnTime2;
    @BindView(R.id.btn_time4)
    Button mBtnTime4;
    @BindView(R.id.btn_slow)
    Button mBtnSlow;
    @BindView(R.id.btn_middle)
    Button mBtnMiddle;
    @BindView(R.id.btn_fast)
    Button mBtnFast;
    @BindView(R.id.btn_brightness_add)
    Button mBtnBrightnessAdd;
    @BindView(R.id.btn_sw_add)
    Button mBtnSwAdd;
    @BindView(R.id.btn_sw_cut)
    Button mBtnSwCut;
    @BindView(R.id.btn_brightness_cut)
    Button mBtnBrightnessCut;
    @BindView(R.id.btn_subsection)
    Button mBtnSubsection;
    @BindView(R.id.btn_auxiliary)
    Button mBtnAuxiliary;
    @BindView(R.id.btn_add)
    Button mBtnAdd;


    protected DeviceCategory mDeviceCategory;



    @Override
    public int getLayoutId() {
        return R.layout.fragment_fanlamp;
    }


    public static ISupportFragment newInstance(DeviceCategory mainItem) {
        Bundle args = new Bundle();
        args.putParcelable(ARG_FANLAMP, mainItem);
        FanLampFragment fragment = new FanLampFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public void init(View rootView) {
        mDeviceCategory = getArguments().getParcelable(ARG_FANLAMP);
        if (mDeviceCategory != null) {
            mTvPage.setText(mDeviceCategory.getName());

        }

        if (LocaleUtil.getLanguage().startsWith("zh")) {
            mBtnAdd.setBackgroundResource(R.drawable.btn_help_n);
            mBtnAdd.setVisibility(View.VISIBLE);
        }else {
            mBtnAdd.setVisibility(View.GONE);
        }
    }


    @Override
    public void onResume() {
        super.onResume();
        if (mDeviceCategory != null) {
            AppManager.getInstance(getContext()).mSelectDeviceCategory = mDeviceCategory;
        }

    }

    @OnClick({R.id.btn_back, R.id.tv_back, R.id.btn_lamp_switch, R.id.btn_fan_switch, R.id.btn_time1, R.id.btn_time2, R.id.btn_time4, R.id.btn_slow, R.id.btn_middle, R.id.btn_fast,
            R.id.btn_brightness_add, R.id.btn_sw_add, R.id.btn_sw_cut, R.id.btn_brightness_cut, R.id.btn_subsection, R.id.btn_auxiliary,R.id.btn_add})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                doBack();

                break;
            case R.id.tv_back:
                doBack();

                break;
            case R.id.btn_subsection://分段
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "0D000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_brightness_add://亮度增加
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "0B000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_sw_add://色温增加
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "09000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_sw_cut://色温减少
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "0A000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_brightness_cut://亮度减少
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "0C000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_lamp_switch://灯开关
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "01000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_fan_switch://风扇开关
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "02000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_auxiliary://辅光
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "0E000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_time1://定时一小时
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "03000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_time2://定时两小时
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "04000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_time4://定时四小时
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "05000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_slow://慢
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "06000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_middle://中
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "07000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;
            case R.id.btn_fast://快
                AppManager.getInstance(mainActivity).commandAdvertise("01", mDeviceCategory.getFamilyId(), mDeviceCategory.getGroupId(), "08000000", "000000", mCurrFamily.getSeed(), mCurrFamily.getFeedback(), 1, "7203");

                break;


            case R.id.btn_add://语音说明提示
                showPopupWindow(mBtnAdd, R.drawable.fl_speech_help_dialog);
                break;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mDeviceCategory = null;

    }

}
